package com.lujianfei.android_actionbar;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MoreActivity extends AppCompatActivity {

    androidx.appcompat.widget.Toolbar toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more);
        toolbar = findViewById(R.id.toolBar);
        setSupportActionBar(toolbar);
        /** 显示带下拉菜单的标题栏 */
        ActionBar supportActionBar = getSupportActionBar();
        if (null != supportActionBar) {
            supportActionBar.setTitle("带下拉菜单的 ActionBar");
            supportActionBar.setDisplayHomeAsUpEnabled(true);
            supportActionBar.setHomeButtonEnabled(true);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.more,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
            {
                finish();
            }
            break;
            case R.id.menu_item_1:
            {
                Toast.makeText(getBaseContext(),"MenuItem1 click",Toast.LENGTH_SHORT).show();
            }
            break;
            case R.id.menu_item_2:
            {
                Toast.makeText(getBaseContext(),"MenuItem2 click",Toast.LENGTH_SHORT).show();
            }
            break;
        }
        return super.onOptionsItemSelected(item);
    }
}
